//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __CBUFFEREDINPUTSTREAM_H__
#define __CBUFFEREDINPUTSTREAM_H__

#include "_CBufferedInputStream.h"

CarClass(CBufferedInputStream)
{
public:
    CARAPI Available(
        /* [out] */ Int32 * pBytes);

    CARAPI Close();

    CARAPI Mark(
        /* [in] */ Int32 readLimit);

    CARAPI IsMarkSupported(
        /* [out] */ Boolean * pSupported);

    CARAPI Read(
        /* [out] */ Byte * pByte);

    CARAPI ReadBuffer(
        /* [out] */ BufferOf<Byte> * pBuffer);

    CARAPI ReadBufferEx(
        /* [in] */ Int32 offset,
        /* [in] */ Int32 length,
        /* [out] */ BufferOf<Byte> * pBuffer);

    CARAPI Reset();

    CARAPI Skip(
        /* [in] */ Int32 length);

    CARAPI constructor(
        /* [in] */ IInputStream * pStream);

    CARAPI constructor(
        /* [in] */ IInputStream * pStream,
        /* [in] */ Int32 defaultBufferSize);

    ~CBufferedInputStream();

    CBufferedInputStream() : m_pIis(NULL), m_pBuf(NULL) {}

private:
    ECode read(BufferOf<Byte> *pBuf, Int32 offset, Int32 len, Int32 *pRead);
    ECode fill();

private:
    IInputStream * m_pIis;
    BufferOf<Byte>* m_pBuf;// we need a automatic updater to update the m_buf,
    Int32 m_pos;
    Int32 m_markpos;
    Int32 m_markLimit;
};

#endif // __CBUFFEREDINPUTSTREAM_H__
